package com.example.xunua_zhinengjiaotong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.xunua_zhinengjiaotong.R;
import com.example.xunua_zhinengjiaotong.utils.ETCLogBean;

import java.util.ArrayList;

public class MyLogListViewAdapter extends BaseAdapter {
    private ArrayList<ETCLogBean> mData =new ArrayList<>();
    private Context context;

    public MyLogListViewAdapter(ArrayList<ETCLogBean> mData, Context context) {
        this.mData = mData;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView == null) {
            convertView=LayoutInflater.from(context).inflate(R.layout.item_lv_etclog,null);
            holder=new ViewHolder();
            holder.tv_money=convertView.findViewById(R.id.lv_etclog_money_tv);
            holder.tv_carid=convertView.findViewById(R.id.lv_etclog_CarId_tv);
            holder.tv_input=convertView.findViewById(R.id.lv_etclog_input_tv);
            holder.tv_out=convertView.findViewById(R.id.lv_etclog_out_tv);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tv_money.setText(mData.get(position).getMoney());
        holder.tv_carid.setText(mData.get(position).getCarId());
        holder.tv_input.setText(mData.get(position).getEtcInTime());
        holder.tv_out.setText(mData.get(position).getEtcOutTime());
        return convertView;
    }

    private class ViewHolder{
        TextView tv_money,tv_carid,tv_input,tv_out;
    }
}
